import org.kwis.msp.lcdui.*;
import java.util.*;


public class GameMemberGroup extends Vector{

	private int direction;

	private int edgeLeft;
    private int edgeRight;
    private int edgeBottom;
    
    private int boundaryLeft;
    private int boundaryRight;
    private int boundaryBottom;
   
	private int stepHorizontal;
    private int stepVertical;
	private Random rnd;

	//------------  GameMemberGroup  »ý¼ºÀÚ  ---------------

	public GameMemberGroup(){

		direction = 1;
		stepHorizontal = 1;
		stepVertical = 1;

		edgeLeft= 10000;
		edgeRight = -10000;
		edgeBottom= -10000;

		rnd = new Random();


	} //GameMemberGroup Constructor

//---------- moveHorizontal------------------

	public void moveHorizontal() 
    {	
        int vstep=0;
        int hstep=stepHorizontal;
        if (edgeBottom >= boundaryBottom) {
            return;
		}
		
        if (direction < 0 && edgeLeft - stepHorizontal < boundaryLeft ||
            direction > 0 && edgeRight + stepHorizontal > boundaryRight) 
        {	
            direction = -direction;
			stepHorizontal=direction;
            vstep = stepVertical;
            hstep = 0;
			
        }//if

		edgeLeft= 10000;
		edgeRight = -10000;
		edgeBottom= -10000;


        for (int i=0; i<size(); i++) 
        {	
            GameMember member = (GameMember)elementAt(i);
            member.move(member.getX() + hstep, member.getY() + vstep);
            member.imageToggler();
            checkEdges(member);

           
        }//for
    
    }//moveHorizontal()

//-----------   moveVertical()  -------------------

	public void moveVertical(){

		edgeLeft=10000;
		edgeRight = -10000;
		edgeBottom = -10000;

		for(int i=0; i<size(); i++){
			GameMember member = (GameMember)elementAt(i);
			member.move(member.getX(), member.getY()+ stepVertical);
			checkEdges(member);
		}//for
		
    } // moveVertical()	


//---------- checkEdges()------------------

	private void checkEdges(GameMember member) 
    {
        if (member.getX() < edgeLeft) 
            edgeLeft = member.getX();
        if (member.getX() + member.getWidth() > edgeRight) 
            edgeRight = member.getX() + member.getWidth();

        if (member.getY() + member.getHeight() > edgeBottom) 
            edgeBottom = member.getY() + member.getHeight();

    }//checkEdges()

    
    public int getBoundaryLeft() { return boundaryLeft; }

    public void setBoundaryLeft(int left) { this.boundaryLeft = left;  }

    public int getBoundaryRight()  {return boundaryRight;}
    
    public void setBoundaryRight(int right) { this.boundaryRight = right; }
    
    public int getBoundaryBottom(){return boundaryBottom;} 

	public void setBoundaryBottom(int bottom){ this.boundaryBottom=bottom;} 

    public int getStepHorizontal(){return stepHorizontal;}

	public void setStepHorizontal(int step) {stepHorizontal = step; direction=step; }
    
    public int getStepVertical(){return stepVertical;}        
        
	public void  setStepVertical(int step){this.stepVertical=step;}  
    




} //GameMemberGroup
